<?php


namespace App\Http\Controllers\Api;


use App\Http\Requests\Api\ImgDetectRequest;
use App\Http\Services\PhotoAI\AipImageService;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;

class ImgDetectController
{

    public function dish(ImgDetectRequest $request)
    {
        if (!is_uploaded_file( $_FILES['file']['tmp_name'])){
            return api()->error(555,'文件未上传！');
        }
        $uploaded_fie = $_FILES['file']['tmp_name'];
        $image = file_get_contents($uploaded_fie);
        $service = new AipImageService();
        $option = $service->make_options(new Collection($request->all()),['top_num','filter_threshold','baike_num']);
        $res = $service->dish($image,$option);
        return api()->success('识别成功',$res);
    }

    public function plant(ImgDetectRequest $request)
    {
        if (!is_uploaded_file( $_FILES['file']['tmp_name'])){
            return api()->error(555,'文件未上传！');
        }
        $uploaded_fie =  $_FILES['file']['tmp_name'];
        $image = file_get_contents($uploaded_fie);
        $service = new AipImageService();
        $option = $service->make_options(new Collection($request->all()),['baike_num']);
        $res = $service->plant($image,$option);
        return api()->success('识别成功',$res);
    }
}
